
import InputManager from "./InputManager";
import { EventTool } from "../Tool/EventTool";




export enum GameState
{
    Ready,
    Pause,
    Start,
    GameOver,
}

export enum GameLanguageType
{
    Chinese,
    English,
}

export default class GameManager
{
    m_currentScene: Laya.Scene3D;
    public get CurrentScene()
    {
        return this.m_currentScene;
    }

    private static m_instance:GameManager;
    public m_GameState:GameState=GameState.Ready;

    private m_camera:Laya.Camera=null;
    public get CurrentSceneCamera()
    {
        return this.m_camera;
    }

    public static s_GameLanguageType=GameLanguageType.Chinese;
    public static GetInstance():GameManager
    {
        if(this.m_instance==null)
        {
            this.m_instance=new GameManager();
        }
        return this.m_instance;
    }


    public Init()
    {  
        
    }


    OnGameLoadOver()
    {
        // Laya.Scene3D.load(KongFuLoader.Instance.s_ScenePath,Laya.Handler.create(this,this.OnLoadSceneComplete.bind(this))); 
    }




    private index=1;
    OnLoadSceneComplete(scene:Laya.Scene3D)
    {
        if (scene==null) 
        {
            // Laya.Scene3D.load(KongFuLoader.Instance.s_ScenePath,Laya.Handler.create(this,this.OnLoadSceneComplete.bind(this))); 
            console.log("正在尝试重新加载");
            EventTool.LogEvent("OnLoadSceneComplete Reload===");
            return;
        }

        this.m_currentScene=scene;
        this.m_currentScene.active=true;
        Laya.stage.addChild(scene);

        Laya.stage.frameRate = Laya.Stage.FRAME_FAST;
        this.m_currentScene.physicsSimulation.fixedTimeStep=1/60;

        this.InitLight();

    }


    InitLight()
    { 
        this.m_camera=this.m_currentScene.getChildByName("Main Camera") as Laya.Camera;
        // let cameraMove:CameraMove=this.m_camera.addComponent(CameraMove);
        let playerSp=this.m_currentScene.getChildByName("Player") as Laya.Sprite3D;
        //  cameraMove.SetFollowTarget(playerSp.transform);
        this.m_camera.enableHDR=false;
        // let lighting=this.m_currentScene.getChildByName("Directional Light") as Laya.DirectionLight;
        //  //灯光开启阴影
        //  lighting.shadowMode = laya.d3.core.light.ShadowMode.None;
        //  //可见阴影距离
        //  lighting.shadowDistance = 300;
        //  //生成阴影贴图尺寸
        //  lighting.shadowResolution = 800;
        //  //生成阴影贴图数量
        //  lighting.shadowPSSMCount = 1;
        //  //模糊等级,越大越高,更耗性能
        //  lighting.shadowPCFType = 1;
    }

    InitPrefabs(){

    }


    InitScene()
    {

    }


    private  s_textureArray:Array<number>=[];
    public OnPlayerChangeSkin()
    {
        this.s_textureArray.length=0;
    }


    public OnGameStart(levelId:string)
    {

       
    }


    private ray:Laya.Ray = new Laya.Ray(new Laya.Vector3(0, 0, 0), new Laya.Vector3(0, 0, 0));
    private hitResult:Laya.HitResult = new Laya.HitResult();
    public PhysicRayCast(from,to,showLine?:boolean)
    {
        if (showLine) 
        {
            var lineSprite:Laya.PixelLineSprite3D = this.m_currentScene.addChild(new Laya.PixelLineSprite3D(1)) as Laya.PixelLineSprite3D;
            lineSprite.addLine(from, to, Laya.Color.RED, Laya.Color.RED);
        }

        this.m_currentScene.physicsSimulation.raycastFromTo(from, to, this.hitResult);
        return this.hitResult;
    }



}